package com.study.web.controller.versionInfo;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.app.domain.bo.AppVersionBo;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import com.study.app.domain.vo.AppVersionVo;
import com.study.app.service.IAppVersionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * App版本信息
 *
 * @author mjzx
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/version")
public class AppVersionInfoController {

    private final IAppVersionService appVersionService;


    /**
     * 根据手机类型获取App历史版本信息展示
     *
     * @param phoneType 1.ios,2.安卓
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/getAppVersion")
    public R<TableDataInfo<AppVersionVo>> getAppVersion(@Valid Integer phoneType, PageQuery pageQuery) {
        AppVersionBo versionBo = new AppVersionBo();
        versionBo.setPhoneType(phoneType);
        TableDataInfo<AppVersionVo> appVersionVoTableDataInfo = appVersionService.queryPageList(versionBo, pageQuery);
        return R.ok(appVersionVoTableDataInfo);
    }

    /**
     * 获取单独版本详情
     *
     * @param id
     * @return
     */
    @SaCheckLogin
    @GetMapping("/getInfo")
    public R<?> getAppVersionInfo(@Valid Long id) {
        return R.ok(appVersionService.queryById(id));
    }


    /**
     * 检测App当前版本是否是最新版本
     *
     * @param phoneType
     * @param versionNumber
     * @return
     */
    @SaCheckLogin
    @GetMapping("/detection")
    public R<?> getDetectionVersion(@Valid Integer phoneType, @Valid Integer versionNumber) {
        return R.ok(appVersionService.checkVersion(phoneType,versionNumber));
    }
}
